package org.example.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.example.annotation.CheckPermission;
import org.example.ourEnum.ExhibitionStatus;
import org.example.pojo.domain.Exhibition;
import org.example.pojo.dto.ExhibitionDto;
import org.example.pojo.dto.PublishExhibitionDto;
import org.example.pojo.vo.ExhibitionToManyArtifactVo;
import org.example.result.Result;
import org.example.service.ExhibitionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/exhibition")
@RestController
@CrossOrigin
public class ExhibitionController {

    @Autowired
    private ExhibitionService exhibitionService;
    /**通过id查看一个展览详细信息(curator,admin)**/
    @CheckPermission({"curator", "admin"})
    @GetMapping("/{id}")
    public Result getExhibitionById(@PathVariable("id")  Integer id) {
        return Result.success("success",exhibitionService.getExhibitionById(id));
    }

    /**分页 查看所有已经公布的展览信息(不会加上展览上所展示文物的信息)(所有角色)**/
    @CheckPermission({"visitor","curator", "admin"})
    @GetMapping("/listPublished")
    public Result getPublishedExhibitions(@RequestParam(defaultValue = "1") int page,
                                          @RequestParam(defaultValue = "10") int size) {
        PageHelper.startPage(page,size);
        return Result.success("success",new PageInfo<>(exhibitionService.getPublishedExhibitions()));
    }

    /**分页 查看所有的展览信息(不会加上展览上所展示文物的信息)(curator,admin)**/
    @CheckPermission({"curator", "admin"})
    @GetMapping("/listAll")
    public Result getAllExhibitions(@RequestParam(defaultValue = "1") int page,
                                    @RequestParam(defaultValue = "10") int size) {
        PageHelper.startPage(page,size);
        return Result.success("success",new PageInfo<>(exhibitionService.getAllExhibitions()));
    }

    /**通过展览的主题名字模糊查询到展览信息(所有角色)**/
    @CheckPermission({"visitor","curator", "admin"})
    @GetMapping("/searchByTitle")
    public Result searchExhibitionsByTitle(@RequestParam("title") String title) {
        return Result.success("通过主题模糊查询成功",exhibitionService.searchExhibitionsByTitle(title));
    }

    /**通过展览的id查询展览的详细信息(会加上展览上所展出的文物信息)(所有角色)**/
    @CheckPermission({"visitor","curator","admin"})
    @GetMapping("/searchDetailById/{id}")
    public Result searchDetailById(@PathVariable("id")  Integer id) {
        return Result.success("查看展览会详细信息成功",exhibitionService.searchDetailById(id));
    }

    /**添加展览(curator,admin)**/
    @CheckPermission({"curator","admin"})
    @PostMapping("/add")
    public Result addExhibition(@RequestBody ExhibitionDto dto) {
        exhibitionService.addExhibition(dto);
        return Result.success("展览添加成功");
    }

    /** 馆长发布草稿展览并借出文物 **/
    @CheckPermission({"admin"})
    @PostMapping("/publish")
    public Result publishExhibition(@RequestBody PublishExhibitionDto dto) {
        exhibitionService.publishExhibition(dto);
        return Result.success("展览发布并借出文物成功");
    }
}
